$(function () {

    let form = layui.form

    form.verify({
        oldPwd: [
            /^[\S]{6,12}$/,
            '密码必须6到12位，且不能出现空格'
        ],
        newPwd: function (value) {

            let oldPwd = $('[name="oldPwd"]').val()
            if (value == oldPwd) {
                return '新密码不能与原密码一值'
            }

        },
        rePwd: function (value) {

            let newPwd = $('[name="newPwd"]').val()
            if (value !== newPwd) {
                return '两次密码输入不一致'
            }

        }


    });


    $('form').on('submit', function (e) {

        e.preventDefault()

        axios({
            method: 'POST',
            url: '/my/updatepwd',
            data: $(this).serialize()
        }).then(function (res) {

            if (res.data.status !== 0) {
                return layui.layer.msg(res.data.message)
            }
            layui.layer.msg('修改成功')
            $('form')[0].reset()
            // window.parent.location.href = '/login.html'

        })

    })



})